<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item><a href="/">商品管理</a></el-breadcrumb-item>
            <el-breadcrumb-item>商品列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 面板 -->
        <el-card class="box-card" style="margin-top:20px">
            <!-- 输入框 -->
            <el-row>
                <el-col :span="12">
                    <div class="grid-content bg-purple">
                        <el-input placeholder="请输入内容" class="input-with-select" v-model="queryinfo.query" clearable @clear='getGoods'>
                            <el-button slot="append" icon="el-icon-search" @click="getGoods"></el-button>
                        </el-input>
                    </div>
                </el-col>
                <el-col :span="12">
                    <div class="grid-content bg-purple-light" style="margin-left:20px">
                        <el-button type="primary" @click="showAdd">添加商品</el-button>
                    </div>
                </el-col>
            </el-row>
            <!-- 表格 -->
            <div style="margin-top:20px">
                <template>
                    <el-table :data="goodsList" border="" style="width: 100%">
                        <el-table-column type='index'></el-table-column>
                        <el-table-column prop="goods_name" label="商品名称" width="500">
                        </el-table-column>
                        <el-table-column prop="goods_price" label="商品价格(元)" width="200">
                        </el-table-column>
                        <el-table-column prop="goods_weight" label="商品重量" width="200">
                        </el-table-column>
                        <el-table-column prop="upd_time" label="创建时间" width="300">
                            <template slot-scope="scope">
                                {{scope.row.upd_time | dataFormat}}
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="176">
                            <template>
                                <el-tooltip content="编辑" placement="top">
                                    <el-button type="primary" icon="el-icon-edit" size="small"></el-button>
                                </el-tooltip>
                                <el-tooltip content="删除" placement="top">
                                    <el-button type="danger" icon="el-icon-delete" size="small"></el-button>
                                </el-tooltip>
                            </template>
                        </el-table-column>
                    </el-table>
                </template>
            </div>
            <!-- 分页 -->
            <div class="block" style="margin-top:20px">
                <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryinfo.pagenum"
                :page-sizes="[1, 2, 5, 10]"
                :page-size="queryinfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
                </el-pagination>
            </div>
        </el-card>
    </div>
</template>

<script>
export default {
    data() {
        return {
            queryinfo:{query:'',pagenum:1,pagesize:5},
            goodsList:[],
            total:0
        }
    },
    created() {
        this.getGoods()
    },
    methods:{
        async getGoods() {
            let {data : res} = await this.$http.get('goods',{
                params:this.queryinfo
            })
            if(res.meta.status != 200) return this.$message.error(res.meta.msg)
            // console.log(res)
            this.goodsList = res.data.goods
            this.total = res.data.total
        },
        handleSizeChange(newPagesize) {
            this.queryinfo.pagesize = newPagesize
            this.getGoods()
        },
        handleCurrentChange(newPagenum) {
            this.queryinfo.pagenum = newPagenum
            this.getGoods()
        },
        showAdd() {
            this.$router.push('/goods/add')
        }
    }
}
</script>

<style lang="less" scoped>

</style>
